package com.face.console.pojo.dto;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * @author Liudehua
 * @explain
 * @date 2021/12/19 11:18
 */
public class User implements UserDetails {

//    public static void main(String[] args) {
//        JwtBuilder jwtBuilder = Jwts.builder();
//        jwtBuilder.setId("001");
//        jwtBuilder.setSubject("Role");
//        jwtBuilder.setIssuedAt(new Date());
//        jwtBuilder.signWith(SignatureAlgorithm.HS256,"12345");
//        Map<String,Object> map = new HashMap<>();
//        map.put("A","a-z");
//        map.put("1","0-10");
//        List<String> list= new ArrayList<>();
//        list.add("add");
//        list.add("del");
//        map.put("list",list);
//        jwtBuilder.claim("data",map);
//        //获取token'
//        String token = jwtBuilder.compact();
//        System.out.println(jwtBuilder.compact());
//        //base64解密
//        String[] split =token.split("\\.");
////        System.out.println(Base64Codec.BASE64.decodeToString(split[0]));//头部
////        System.out.println(Base64Codec.BASE64.decodeToString(split[1]));//载体
////        System.out.println(Base64Codec.BASE64.decodeToString(split[2]));//签名
//        Claims cla = Jwts.parser()
//                .setSigningKey("123456")
//                .parseClaimsJws(token)
//                .getBody();
//        System.out.println("id:" + cla.getId());
//        System.out.println("sub" + cla.getSubject());
//        System.out.println("issuedAt" + cla.getIssuer());
//        System.out.println("data:"+cla.get("data"));
//
//
//    }

    private String username;
    private String password;
    private List<GrantedAuthority> authorities;

    public User(String username, String password, List<GrantedAuthority> authorities) {
        this.username = username;
        this.password = password;
        this.authorities = authorities;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setAuthorities(List<GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
